home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Action Atoms [inaa] Example / atom2.c < prev    next >
Encoding:
Text File  |  1996-10-01  |  8.3 KB  |  233 lines  |  [TEXT/MPS ]

  1. //
  2. //    atom2.c
  3. //
  4. //        Demonstration of a format2 action atom and compatibility with
  5. //        Installer Engine 4.1.
  6. //
  7. //        Under Installer 4.0.3, a dialog is provided that allows the
  8. //        user to select the return value for the action atom. 
  9. //
  10. //        Scriptwriters should be aware that the return values
  11. //        and the actions that they invoke from the installer
  12. //        are different depending on which format of action atom
  13. //        is being used. 
  14. //
  15. //        It is recommended that the constants 
  16. //            'kActionAtomResultFatalError'    <= -1
  17. //            'kActionAtomResultContinue'        <= 0
  18. //            'kActionAtomResultCancel'        <= 1
  19. //        be used when working with format2 action atoms.
  20. //        These constants are defined in "ActionAtomHeader.h"
  21. //        and are designed for use with format2 action atoms.
  22. //
  23. //        NOTE: Displaying dialogs from within action atoms and other
  24. //        code resources is discouraged.  Installer scripts that
  25. //        display dialogs from within code resources will not work
  26. //        when running under Installer Engine 4.1.  This example shows
  27. //        you how you can write action atom code that will display a
  28. //        dialog under Installer 4.0.3 and still be compatible with
  29. //        Installer Engine 4.1.  For more information on script
  30. //        compatibility with Installer Engine 4.1 see the "Engine 4.1
  31. //        Compatiblity Issues" document in the Installer 4.1 folder of
  32. //        the Installer SDK.
  33. //
  34. //      Additionally, this example completely ignores good user
  35. //        interface design practices for the purpose of demonstrating the
  36. //      installer in regards to return values from an action atom.
  37. //
  38. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  39. //
  40.  
  41.  
  42. #include <Traps.h>
  43. #include <Types.h>
  44. #include <dialogs.h>
  45. #include <TextUtils.h>
  46.  
  47. // these line has been added for Wasabi Installer Debugger support
  48. #include "ActionHandlerHeader.h"
  49.  
  50. // this line replaces #include "ActionAtomHeader.h" used in previous 4.0.3 action atoms
  51. #include "InstallerScript.h"
  52.  
  53. // this is needed for highlighting the default button in dialog
  54. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  55.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  56.  
  57. // this is used to print one line out to the Wasabi Installer Debugger 
  58. void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 );
  59.  
  60. // print the parameter block record information to Wasabi Installer Debugger
  61. void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr );
  62.  
  63. // NOTE: The name of this function 'ActionAtomFormat2' should
  64. // match that specified in the -m option for the line in the
  65. // makefile that compiles this action atom.
  66. ActionAtomResult ActionAtomFormat2( ActionAtom2PBPtr atomRecPtr )
  67. {
  68.  
  69.     DialogPtr    theDialog;                        // for dialog
  70.     OSErr        theOSError = 0;                    // for errors
  71.     
  72.     short        theItemHit;                        // gets user response from ModalDialog()
  73.     short        iType;                            // gets control type from GetDItem()
  74.     Handle        iHandle;                        // gets control handle from GetDItem()
  75.     Rect         iRect;                            // gets control rect from GetDItem()
  76.     
  77.     short        currRadioButton = 2;            // current selected radio button
  78.     short        gettingUserResponse = true;        // flag for while loop
  79.     
  80.     short        theStatus = 0;                    // value to return from function
  81.  
  82.     // print the parameter block record information to Wasabi Installer Debugger
  83.     PrintAAParamBlock( atomRecPtr );
  84.  
  85.     // retrieve DLOG/DITL 130 from compiled resource script
  86.     theDialog = GetNewDialog( 130, nil, (WindowPtr) -1 );
  87.  
  88.     // Installer Engine 4.1 will indicate that a window cannot be displayed by
  89.     // patching GetNewDialog and returning NULL.
  90.     if( theDialog != NULL )                    
  91.     {
  92.         // We are running with Installer 4.0.3
  93.         // Display the dialog.
  94.  
  95.         // activate OK button when enter or return key is pressed
  96.         theOSError = SetDialogDefaultItem( theDialog, 1 );
  97.     
  98.         // set up the radio button group ( controls 2 - 4 )
  99.         GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
  100.         SetCtlValue( (ControlHandle) iHandle, 1 );    
  101.         
  102.         GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
  103.         SetCtlValue( (ControlHandle) iHandle, 0 );    
  104.         
  105.         GetDItem( theDialog, 4, &iType, &iHandle, &iRect);
  106.         SetCtlValue(  (ControlHandle) iHandle, 0 );    
  107.         
  108.         // select the new dialog
  109.         SelectWindow( (WindowPtr) theDialog );
  110.         
  111.         // show the new dialog
  112.         ShowWindow( (WindowPtr) theDialog );
  113.         
  114.         // keep getting response from user until
  115.         // the OK is activated in the new dialog
  116.         gettingUserResponse = true;
  117.         while ( gettingUserResponse )
  118.             {
  119.             // get user selection from the new dialog
  120.             ModalDialog( nil, &theItemHit );
  121.             
  122.             switch ( theItemHit )
  123.                 {
  124.                 // first control is the OK key
  125.                 case( 1 ) : 
  126.                             // exit loop
  127.                             gettingUserResponse = false;
  128.                             break;
  129.                             
  130.                 // all other controls in dialog are radio buttons
  131.                 default :     
  132.                             // continue with loop
  133.                             gettingUserResponse = true;
  134.                             
  135.                             // if the radio button selection changed
  136.                             if ( currRadioButton != theItemHit )
  137.                                 {
  138.                                 // turn previous radio button off
  139.                                 GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
  140.                                 SetCtlValue(  (ControlHandle) iHandle, 0 );    
  141.             
  142.                                 // turn current radio button on
  143.                                 GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
  144.                                 SetCtlValue(  (ControlHandle) iHandle, 1 );    
  145.             
  146.                                 // save current radio button choice
  147.                                 currRadioButton = theItemHit;
  148.                                 }
  149.                             break;
  150.                 }// switch
  151.     
  152.             }// while
  153.             
  154.         // get rid of the new dialog
  155.         DisposDialog( theDialog );
  156.     
  157.         // select a value to return from this function according to
  158.         // which radio button was selected in the dialog
  159.         switch ( currRadioButton )
  160.             {
  161.             // return 0
  162.             case( 2 ) : theStatus = kActionAtomResultContinue;    // user selected return 0
  163.                         break;
  164.                         
  165.             // return 1
  166.             case( 3 ) : theStatus = kActionAtomResultCancel;    // user selected return 1
  167.                         break;
  168.                         
  169.             // return -1
  170.             case( 4 ) : theStatus = kActionAtomResultFatalError;// user selected return -1
  171.                         break;
  172.             }
  173.             
  174.         // return value selected by user in dialog
  175.         return( theStatus );
  176.     }// if theDialog != NULL
  177.     else
  178.     {
  179.         // We are running under Installer Engine 4.1, which doesn't interact with user.
  180.         // Do default action here rather than trying to display a dialog.
  181.         // Let's say the default action for this example is to return kActionAtomResultContinue.
  182.         
  183.         return (kActionAtomResultContinue);
  184.     }
  185. }
  186.  
  187. // shoot one line of text out to the Wasabi Installer Debugger
  188. void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
  189. {
  190.     long    theResult;
  191.     RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );    
  192. }
  193.  
  194. // print a series of formatted lines describing the parameter block
  195. // received by the action atom out to the Wasabi Installer Debugger
  196. void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr )
  197. {
  198.     Str255        numStr;
  199.     
  200.     PrintLine( atomRecPtr->fCallBackProcPtr, "\p\n", "\pParameter Block for Action Atom Format2...", "\p", "\p" );
  201.     
  202.     NumToString( atomRecPtr->fMessageID, numStr );
  203.     PrintLine(   atomRecPtr->fCallBackProcPtr, "\p", "\pfMessageID : ", numStr,  "\p" );
  204.     
  205.     NumToString( (long) atomRecPtr->fStaticDataHdl, numStr );
  206.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfStaticDataHdl : ", numStr, "\p", "\p" );
  207.     
  208.     NumToString( (long) atomRecPtr->fTargetVRefNum, numStr );
  209.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfTargetVRefNum : ", numStr, "\p", "\p" );
  210.     
  211.     NumToString( (long) atomRecPtr->fTargetFolderDirID, numStr );
  212.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfTargetFolderDirID : ", numStr, "\p", "\p" );
  213.     
  214.     NumToString( (long) atomRecPtr->fSystemVRefNum, numStr );
  215.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfSystemVRefNum : ", numStr, "\p", "\p" );
  216.     
  217.     NumToString( (long) atomRecPtr->fSystemBlessedDirID, numStr );
  218.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfSystemBlessedDirID : ", numStr, "\p", "\p" );
  219.     
  220.     NumToString( (long) atomRecPtr->fRefCon, numStr );
  221.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfRefCon : ", numStr, "\p", "\p" );
  222.     
  223.     NumToString( (long) atomRecPtr->fDoingInstall, numStr );
  224.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfDoingInstall : ", numStr, "\p", "\p" );
  225.     
  226.     NumToString( (long) atomRecPtr->fDidLiveUpdate, numStr );
  227.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfDidLiveUpdate : ", numStr, "\p", "\p" );
  228.     
  229.     NumToString( (long) atomRecPtr->fInstallerTempDirID, numStr );
  230.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfInstallerTempDirID : ", numStr, "\p", "\p\n" );
  231.     
  232. }
  233.